﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SmartProject.Entity;

using FluentNHibernate.Mapping;

namespace SmartProject.Mapping
{
    public class RoleMap : ClassMap<Role>
    {
        public RoleMap()
        {
            Table("SmartProject_Role");
            Id(x => x.Id).Column("RoleId");
            Map(x => x.Name).Not.Nullable();
            HasManyToMany<Permission>(x => x.Permissions)
                .Table("SmartProject_RolePermissions")
                .ParentKeyColumn("RoleId")
                .ChildKeyColumn("PermissionId")
                .Fetch.Join();
            HasManyToMany<User>(x => x.Users)
                .Table("SmartProject_UserRoles")
                .ParentKeyColumn("RoleId")
                .ChildKeyColumn("UserId")
                .LazyLoad();
            Map(x => x.Active).Not.Nullable();
            Map(x => x.Created).Not.Nullable();
        }
    }
}
